package utils;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//给Spring管理
@Component
//切面类
@Aspect
public class TransactionManager {

    //在dao任何一个类的任何方法之前
//    @Before("execution(* dao.*.*(..))")
//    public void begin() {
//        System.out.println("开启事务");
//    }

    //在dao任何一个类的任何方法之后
//    @After("execution(* dao.*.*(..))")
//    public void commit() {
//        System.out.println("提交事务");
//    }

    @Pointcut("execution(* dao.*.*(..))")
    public void pc1() {
        System.out.println("中间事务");
    }

    @Before("pc1()")
    public void begin() {
        System.out.println("开启事务");
    }

    //在dao任何一个类的任何方法之后
    @After("pc1()")
    public void commit() {
        System.out.println("提交事务");
    }

    @Around("pc1()")
    public Object PrintExecuteTime(ProceedingJoinPoint p) throws Throwable {
        long time1 = System.currentTimeMillis();
        Object object = p.proceed();
        long time2 = System.currentTimeMillis();
        System.out.println("---time："+(time2 - time1));
        return object;

    }
}
